package com.ruoyi.project.game.topicgame.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.game.topicgame.domain.TopicGame;
import com.ruoyi.project.game.topicgame.service.ITopicGameService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 主题游戏列表Controller
 * 
 * @author shixiangwen
 * @date 2020-02-12
 */
@Controller
@RequestMapping("/game/topicgame")
public class TopicGameController extends BaseController {
	private String prefix = "game/topicgame";

	@Autowired
	private ITopicGameService topicGameService;

	@RequiresPermissions("game:topicgame:view")
	@GetMapping()
	public String topicgame() {
		return prefix + "/topicgame";
	}

	/**
	 * 查询主题游戏列表列表
	 */
	@RequiresPermissions("game:topicgame:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TopicGame topicGame) {
		startPage();
		List<TopicGame> list = topicGameService.selectTopicGameList(topicGame);
		return getDataTable(list);
	}

	/**
	 * 导出主题游戏列表列表
	 */
	@RequiresPermissions("game:topicgame:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(TopicGame topicGame) {
		List<TopicGame> list = topicGameService.selectTopicGameList(topicGame);
		ExcelUtil<TopicGame> util = new ExcelUtil<TopicGame>(TopicGame.class);
		return util.exportExcel(list, "topicgame");
	}

	/**
	 * 新增字典类型
	 */
	@GetMapping("/add/{topicId}")
	public String add(@PathVariable("topicId") Long topicId, ModelMap mmap) {
		mmap.put("topicId", topicId);
		return prefix + "/add";
	}

	/**
	 * 新增保存主题游戏列表
	 */
	@RequiresPermissions("game:topicgame:add")
	@Log(title = "主题游戏列表", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TopicGame topicGame) {
		return toAjax(topicGameService.insertTopicGame(topicGame));
	}

	/**
	 * 修改主题游戏列表
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		TopicGame topicGame = topicGameService.selectTopicGameById(id);
		mmap.put("topicGame", topicGame);
		return prefix + "/edit";
	}

	/**
	 * 修改保存主题游戏列表
	 */
	@RequiresPermissions("game:topicgame:edit")
	@Log(title = "主题游戏列表", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TopicGame topicGame) {
		return toAjax(topicGameService.updateTopicGame(topicGame));
	}

	/**
	 * 删除主题游戏列表
	 */
	@RequiresPermissions("game:topicgame:remove")
	@Log(title = "主题游戏列表", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(topicGameService.deleteTopicGameByIds(ids));
	}
}
